package com.mikepenz.app.activity;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TextView;

import com.daimajia.slider.library.Animations.DescriptionAnimation;
import com.daimajia.slider.library.Indicators.PagerIndicator;
import com.daimajia.slider.library.SliderLayout;
import com.daimajia.slider.library.SliderTypes.BaseSliderView;
import com.daimajia.slider.library.SliderTypes.TextSliderView;
import com.mikepenz.app.R;
import com.mikepenz.bean.CarBean;
import com.mikepenz.presenter.ProductPresenter;
import com.mikepenz.presenter.imp.ProductPresenterImp;
import com.mikepenz.utils.CookicUntil;
import com.mikepenz.view.ProductView;
import com.quickdv.activity.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.InjectView;

/**
 * Created by lilongfei on 15/5/10.
 */
public class ProductActivity extends BaseActivity implements View.OnClickListener, BaseSliderView.OnSliderClickListener, AdapterView.OnItemClickListener, ProductView {


    //    CustomListView other_service_lv;
    CarBean car;
    @InjectView(R.id.slider)
    SliderLayout slider;
    @InjectView(R.id.custom_indicator2)
    PagerIndicator customIndicator2;
    //    @InjectView(R.id.product_order)
//    Button productOrder;
//    @InjectView(R.id.product_get)
//    Button productGet;
//    @InjectView(R.id.product_car_linear)
//    LinearLayout productCarLinear;
    @InjectView(R.id.product_location)
    TextView productLocation;
//    @InjectView(R.id.product_instance)
//    TextView productInstance;
    @InjectView(R.id.product_phone)
    ImageView productPhone;
    @InjectView(R.id.product_notify)
    TextView productNotify;
    @InjectView(R.id.product_notify2)
    TextView productNotify2;
    @InjectView(R.id.product_notify3)
    TextView productNotify3;

    ProductPresenter presenter;
    Toolbar toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Handle Toolbar

    }

    @Override
    public int getLayoutID() {
        return R.layout.activity_product;
    }

    @Override
    public void initView() {

        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        productPhone.setOnClickListener(this);
        if (getIntent().getExtras() != null) {
            String from = getIntent().getExtras().getString(CookicUntil.FROM);
//            if (from != null)
//                productCarLinear.setVisibility(View.GONE);
        }

//        productGet = findView(R.id.product_get);
//        productOrder = findView(R.id.product_order);
//        productCarLinear = findView(R.id.product_car_linear);
//        productGet.setOnClickListener(this);
//        productOrder.setOnClickListener(this);
        presenter.assignment();
    }

    @Override
    public void initActionbar() {
        getSupportActionBar().setTitle("租车详情");
    }

    @Override
    public void initData() {
        presenter = new ProductPresenterImp(this);
    }

    @Override
    public void assignment(CarBean carBean) {
        if (carBean.getCarName() != null)
            getSupportActionBar().setTitle(carBean.getCarName());
        productNotify.setText(carBean.getDescription());
        if (carBean != null)
            productNotify2.setText("*车辆类型 :" + carBean.getCarType());
        if (carBean.getRegistDate() != null && carBean.getRegistDate().length() > 8)
            productNotify3.setText("*车辆注册时间 :" + carBean.getRegistDate().substring(0, 8));
        else
            productNotify3.setText("*车辆注册时间 :");


        initImageSlider(carBean.getPic(),carBean.getCarName());
    }

    private void initImageSlider(List<String> pic,String des) {
        SliderLayout mDemoSlider = (SliderLayout) findViewById(R.id.slider);

        if (pic == null) {
            pic = new ArrayList<>();
            pic.add("正面");
        }

        for (String name : pic) {
            TextSliderView textSliderView = new TextSliderView(this);
            // initialize a SliderLayout
            textSliderView
                    .description(des).image(CookicUntil.IMG_URL + name)
                    .image(R.drawable.notpic)
                    .setScaleType(BaseSliderView.ScaleType.Fit)
                    .setOnSliderClickListener(this);

            //add your extra information
//            textSliderView.getBundle()
//                    .putString("extra", name);

            mDemoSlider.addSlider(textSliderView);
        }
        mDemoSlider.setPresetTransformer(SliderLayout.Transformer.DepthPage);
        mDemoSlider.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
        mDemoSlider.setCustomAnimation(new DescriptionAnimation());
        mDemoSlider.setDuration(4000);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
//            case R.id.product_get:
//                presenter.OnSentClick();
//                break;
//            case R.id.product_order:
//                presenter.OnOrderClick();
//                break;
            case R.id.product_phone:
                presenter.OnPhoneClick();
                break;
        }

//        startActivity(action, bundle);
    }

    @Override
    public void onSliderClick(BaseSliderView slider) {

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    }
}
